<template>
  <!--循环菜单信息-->
  <div>
    <template v-for="item in this.menuList">
      <!--子菜单-->
      <el-submenu
        :disabled="item.disabled"
        :index="item.id + ''"
        v-if="item.children.length > 0"
        :key="item.id + ''"
      >
        <template slot="title" style="padding-left: 100px">
          <i :class="item.icon"></i>
          <span slot="title">{{ item.menuName }}</span>
        </template>
        <!--递归的方法是循环菜单信息-->
        <MenuTree :menu-list="item.children"></MenuTree>
      </el-submenu>
      <!--父级菜单信息-->
      <!-- disabled  是否启用菜单，表示菜单是否可以点击
           index 路由跳转的地址
           route 存在缓存中的路由地址
           -->
      <el-menu-item
        v-else
        :disabled="item.disabled"
        :index="item.url"
        :route="item.url"
        @click="savePath(item.url)"
        :key="item.id"
        style="padding-left: 50px"
      >
        <i :class="item.icon"></i>
        <span slot="title">{{ item.menuName }}</span>
      </el-menu-item>
    </template>
  </div>
</template>

<script>
export default {
  name: "MenuTree",
  props: ["menuList"],
  methods: {
    savePath(path) {
      window.sessionStorage.setItem("activePath", path);
    },
  },
};
</script>

<style scoped>
.el-menu--collapse span,
.el-menu--collapse i.el-el-submenu__icon-arrow {
  height: 0;
  width: 0;
  overflow: hidden;
  visibility: hidden;
  display: inline-block;
}
</style>
